<?php

class Adept_Db_Query_Insert extends Adept_Db_Query_Abstract
{
    protected $into;
    protected $values = array();

    /**
     * @return string
     * @throws Adept_Db_Query_Exception
     */
    public function __toString()
    {
        $sql = 'INSERT INTO ' . $this->into;

        if (count($this->values) > 0) {
            $sql .= "\n\t";
            $sql .= '(' . implode(', ', array_keys($this->values)) . ')';
            $sql .= "\n\t";
            $sql .= 'VALUES (' . implode(', ', array_values($this->values)) . ')';
        } else {
            throw new Adept_Db_Query_Exception();
        }
        return $sql;
    }

    public function value($key, $value)
    {
        $key = "`{$key}`";
        $this->values[$key] = $value;
        return $this;
    }

    public function values($values)
    {
        foreach ($values as $key => $value) {
            $this->value($key, $value);
        }
        return $this;
    }

    public function into($into)
    {
        $this->into = "`{$into}`";
        return $this;
    }

    public function bind($bind)
    {
        $this->value($bind, ":{$bind}:");
        return $this;
    }

    public function binds($binds)
    {
        foreach ($binds as $bind) {
            $this->bind($bind);
        }
    }

}